package cn.iocoder.yudao.module.engine.controller.app.timepackage;

import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.engine.controller.app.timepackage.vo.AppTimePackagePageReqVO;
import cn.iocoder.yudao.module.engine.controller.app.timepackage.vo.AppTimePackageRespVO;
import cn.iocoder.yudao.module.resource.api.ITimePackageApi;
import cn.iocoder.yudao.module.resource.api.model.timepackage.TimePackageDTO;
import cn.iocoder.yudao.module.resource.api.model.timepackage.TimePackagePageReqDTO;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "用户 APP - 时长套餐")
@RestController
@RequestMapping("/lm/time-package")
@Validated
public class AppTimePackageController {

    @Resource
    private ITimePackageApi timePackageApi;

    @GetMapping("/get")
    @Operation(summary = "获得时长套餐")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthenticated
    public CommonResult<AppTimePackageRespVO> getTimePackage(@RequestParam("id") String id) {
        TimePackageDTO timePackage = timePackageApi.getTimePackage(id);
        return success(BeanUtils.toBean(timePackage, AppTimePackageRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得时长套餐分页")
    public CommonResult<PageResult<AppTimePackageRespVO>> getTimePackagePage(@Valid AppTimePackagePageReqVO pageReqVO) {
        final TimePackagePageReqDTO reqDTO = BeanUtils.toBean(pageReqVO, TimePackagePageReqDTO.class);
        reqDTO.setListingStatus(1); // 上架
        PageResult<TimePackageDTO> pageResult = timePackageApi.getTimePackagePage(reqDTO);
        return success(BeanUtils.toBean(pageResult, AppTimePackageRespVO.class));
    }

}